change loop and output file