Refactoring in preparation for JSON plan emitter