Tidy-up of code