optimization of the concatenate function