reduce symbol dependencies between files and therefore make it easier to write unit tests. The diff is large, but the actual code changes are pretty small.