Refactor duplicated code. NFC.