Optimization now uses sets of hashes.