Fixed nested if statements