fix INVALID_STATE_ERR bug