fixed logic bug