refactoring: do not duplicate code