Refactor for ternary operator