Refactoring with ternary and union operator.