Corrected bug on ternary operation