  Let $A$ be a commutative noetherian ring, $\frak a$ be an ideal of $A$, $m,n$
be non-negative integers and let $M$ be an $A$-module such that
$\Ext^i_A(A/\frak a,M)$ is finitely generated for all $i\leq m+n$. We define a
class $\cS_n(\frak a)$ of modules and we assume that $H_{\frak
a}^s(M)\in\cS_{n}(\frak a)$ for all $s\leq m$. We show that $H_{\frak a}^s(M)$
is $\frak a$-cofinite for all $s\leq m$ if either $n=1$ or $n\geq 2$ and
$\Ext_A^{i}(A/\frak a,H_{\frak a}^{t+s-i}(M))$ is finitely generated for all
$1\leq t\leq n-1$, $i\leq t-1$ and $s\leq m$. If $A$ is a ring of dimension $d$
and $M\in\cS_n(\frak a)$ for any ideal $\frak a$ of dimension $\leq d-1$, then
we prove that $M\in\cS_n(\frak a)$ for any ideal $\frak a$ of $A$.
