Fixing minor logic error