some more refactoring to make the code smaller