Arranged code to look better. Added comments.

Left for team to finish.