fixed logic flaw