Fixed errors

fixed logic errors