Refactoring stuff.  This commit might be broken.