minor refactoring to reduce the amount of code