Optimization for BuildUniqueDict