Bug fix

This commit fixes one bug and one logic error.