Move merging content with state dependent data into engine.

Part of the process of refactoring for #1.