Fixed small logic error