Add javadocs, code cleanup