Refactoring thread

Fair warning: this code is not intended to run just yet. As I was refactoring the functions I realized I had questions for Dan and Co. and decided to put them up on github in order to avoid another long email thread. I'll try to tag people in specific comments to make those salient to relevant folks.