Add tests for merge/clone

Fix two bugs in merge.js