General code tidy up and some work towards 366163
19 files changed