cw4: Refactors and optimisations