Added Javadoc, and made lots of improvements.