added more powerful variants of foldGen (foldGen') and sample' (runGen)