Refactoring to use ternary operators