Refactor for cleanliness. Add lots of documentation to the header file.