Added javadocs and various fixes