Implemented test for counting.
Fixed a huge bug in merging, that was causing counts to be wrong. Also other stuff.