Template and split mongo refactoring

Not yet ready to merge but big enough to require extensive review. I'm hoping to submit it for final review before 13 June.

@jzoldak @cpennington @chrisndodge @shnayder