Added switch statement and cleaned up code.