refactoring: remove duplicate code