Having trouble with conditional logic going the wrong way