Cleanups and optimisations.