made range merging more robust