Simplify code using a ternary