Move the merge operation to an independent module

So that we can easily create a command-line tool.
Fix 2 bugs
Use cPickle to speed up dump/load