Added javadoc and some comments to code.