Added tests and javadoc.