Implement merge operation and cover it with test.