Refactored the cast switch statement.