change merge logic to ensure fields are generated in the same order they are in the layout