Structured classes for merge.
Factored out the construction of the shape.
Consistent naming of template parameters.