Reorganization and Documentation

Moved some code around so that it makes more sense and added some
simple documentation to break up code and increase readability.