fixing logic error