Refactoring and optimisations.