Refactoring: remove code duplication introduced in the previous patch.