Add tests and javadoc