Fix bug in finishTrial