Change ternary operator to if else statement