Cleanup: significantly simplify namespace management code