refactored code using if statemetns instead of switch