move ternary operator test at the end