Improve javadoc and add tests