Corrected the minimize bug and printed the output to a file