Do some optimisations and refactoring to sanitise.