Fixed bugs. Improved tests. Fixed javadoc.