Further tidy-up of code