Fixed bug that produced wrong merging