Trellisupdates

I have squashed most commits and cleaned up the code considerably.
The code should be ready to be merged without conflicts now.

Thanks
Achilleas