cd755bd646
This refactor will hopefully pave the way for further refactors that will make this code easier to understand and work with. Fixes #9.