Refactor to avoid code duplication. NFC.