Fixed keyboard interrupt errors
Clearing output file
Changed output to a function