This is the overall structure of the program, and what it does.
The closed procedure stacks above expand into the following.