remixing kyles stuff. made functions and gross global variables. changed
path and output path to better names.