refactoring if-else to case-when