Completed part d: save results to txt file. TO DO: write-up (part e)