basic code to set up and tear down trials
added scripts to refactor close_trial
more refactoring