fix bug in automatic merge function