REfactor to use if elseif instead of switch clause