Fixes #2801: fix logic error and avoid error about not function