Rearranged code for Style

Moved the code around and added comments in an attempt to make the
code more readable.