Correctings logic error