refactor and minor improvement

'merge' now support text files
optimization for performance