cleaned code up and got it to print to the file