Doing some tidying and optimisations