Modified the example to use global variables.