Adding javadocs, code cleanup and improvements.