now it works and adapts to the size of the stack as the program executes.