Working out ternary and expression logic