big refactor - not completely finished probably, but alll tests that should be passing are passing again, and performance is nigh equivalent to what it was prior to this commit.