Fixed erroneous conditional logic