Fix exiting namespace when it's the last child (#223), clean up surrounding code
Merge pull request #228 from oneeman/fix-exiting-namespace

Fix exiting namespace when it's the last child (#223)