Add trials, and trial-attachments; cleanup and refactor