updated hash sets algorithm