Hierarchical Decompositions and Termination Analysis for Generalized Planning