Work for namespace handling.

A lot of work for namespace handling, refactoring, tests, javadocs.