Bug fix closing files in merge function loop.