Bug fix: logic error on exception handling