fixed bug: thows exception if output file is same as input file