Refactor using the ternary operator