trying to fix a logic error