Major fix back to working condition.

Rewrote a number of system classes and restructured overall design.
Fixed circular dependences and uninitialised variable problem.