refactored code using if/elseif/else