clean up and optimisations