Made all functions take datasets and filenames as parameters instead of taking global variables.