Merge instead of calling << in a loop