Improve default namespace handling and some code cleanup