Added tests, improved javadoc, documentation