FIX: Fix trial ID function

Ready for review/merge @rkmaddox. Would be good to have before the afternoon tomorrow (sorry for the short notice).
Same as above.