Modification to the combine() function. It is actually quite complicated to
make it work properly and efficiently!