refactoring some shared code