Minor refactoring to reduce code duplication