refactored code and removed switch statements