Performance improvements for nunique method.