simulate recursion stack