fix logic error