a bit of refactoring to make it more readable