Fixed the logic error