fixed logic error