Refactor by extracting methods from the deduplication code