Changed scoping for if and ifelse block (vars declared inside are only seen inside