moved composeTrial function here from Display.