More cleaning up and optimisations