Some tidying-up of code