Masses of updates to both tidy code, make it scalable and fix a load of errors.
This is a version that works