faster implementation based on unique comparisons
fixed frequency errors
Merge branch 'master' into unique
added memory cap