refactoring, little optimisations