Refactored KeyUp method to switch and helper method.