Added javadoc and edited for legibility