tidy
misc edits
misc optimisations and simplification