fixed logic problem