fix bug with namespaces not being closed