Simple conditional logic not working