fixed logic problems