code clean up and printing data to file