Some tidying of code