Added javadocs and fixed formatting. Previous commit did not include all changes.