Refactoring: replace verbose if/else blocks with ternary operator