MOAR refactoring and optimisation