Merge fixes

Hello Kevin,

we were trying to do merge on multiple ranges and we ran into some bugs:

  * when merging multiple ranges an exception was raised
  * the logic for intersections wasn't correct

We've added some tests and code to fix the issues.

Tom.