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.
Declaring and modifying global variables is highly discouraged in python (see [this](https://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Global_variables), the section on Global variables [here](http://blog.notdot.net/2009/11/Python-Gotchas)). It also leads to minor slowdowns. What I'm doing is passing a reference to a dictionary to each function and creating keys in this dictionary for our variables. We could alternatively define a class for this dictionary and set its attributes/properties, but I'm trying to keep this as mechanically simple as possible to avoid slowdowns.