The Cohen-Lenstra heuristics, moments and $p^j$-ranks of some groups