Xtrial and refactoring

Sorry, the changes are not broken down.
Merge pull request #7 from thehyve/xtrial

Xtrial and refactoring