Fixed bug when using nested if-then-else statements