Some cleanup and optimisations...