fixed small logic error