javadoc and Exception handling improvements.

Also added and re-arranged unit tests.