Added functions/cell to automate creation of text files in which to save parameters. Also wrapped most of code in functions.