a bit of refactoring to ease code reading