Refactor: rearrange everythnig in the file and add comments.
This will completely screw with any merges, but I think we've
diverged from the sequental version already.