Fix namespace for more nesting levels
Fix errors if namespaces are undefined