Added scope checking for if statements