If $\mathfrak{X}$ is a class of groups, we define a sequence $\mathfrak{X}_{1},\mathfrak{X}_{2},\ldots ,\mathfrak{X}_{k},\ldots$ of group classes by putting $\mathfrak{X}_{1}=\mathfrak{X}$ and choosing $\mathfrak{X}_{k+1}$ as the class of all groups whose nonnormal subgroups belong to $\mathfrak{X}_{k}$. In particular, if $\mathfrak{A}$ is the class of abelian groups, $\mathfrak{A}_{2}$ is the class of metahamiltonian groups, that is, groups whose nonnormal subgroups are abelian. The aim of this paper is to study the structure of $\mathfrak{X}_{k}$-groups, with special emphasis on the case $\mathfrak{X}=\mathfrak{A}$. Among other results, it will be proved that a group has a finite commutator subgroup if and only if it is locally graded and belongs to $\mathfrak{A}_{k}$ for some positive integer $k$.