Fix bugs in trial creation