a bit of refactoring