First implementation of merge operation.