Added printing to file

Added printing to file and cleaned up code
added printing to file