fixing a logic error