Fix small bugs with merge function.