added output function. write in the text file after 1st run. only best one