Refactoring case statement. Fixes #1