Use stack for generation