Complete rebuild from earlier version. WIP.
Synchronise some changes