minor refactoring: remove duplicate code