Added tests and javadoc