Perf refactoring

One for you to review @dchambers