code changes to handle start and stop of experiment and end writing data to the files