added an output file to save values in .txt file. some adjustments in several files