use ternary operator to simplify code