Add initial unit tests for difference calculations and some (large?) performance improvements for primary-key based merging.