fix the logic error