Externalized merging, started unittest, fixed npe