restructured conditional logic so it makes sense