OK, finished this stupid bloody refactor, committing before tidying up