General optimisation/refactoring to clean-up the codebase