Added functionality to handle changing files and saving the results properly.