fixed logic of if statement