Added a few clarifying comments and changed the file organization a bit.