made numelem(D, X) take into account all levels up to X