Refactor case statement, add comments