fix some bugs that prevented repeated calling of ir_init and ir_finish