Refactored handler to remove giant if statement.