Started a more reasonable rewrite of this stuff.