full rewrite, names order retained, uses minhits, faster