Refactored code to replace if conditions with dict objects