changed nesting of if statements