Significantly improve basicSet (based on a patch by Louis Wasserman)