refactor merge to allow late discovery of sources