Refactoring. switch to if-else