Some refactoring to avoid code duplication.