minor refactoring & optimisations