Rearranged code (NO code changes)

I moved code around to make more sense when looking through and added a
few more comments. There was not changes to the actual code.