Begin adding comments and rearranging code

Mainly just dividing up main sections, and grouping components of the
program by type.