Refactored for DRY.