some refactoring for DRY