refactor if/else statement with ternary evaluator