more optimisations / refactorings