Fixed if/endif nesting bug