Refactoring to avoid code duplication.