optimization: avoiding assignment by using if instead of ternary operator