Fixing logic error