Refactored out more methods and simplified the case statement.