refactor to use ternary operator