Eliminate the use of global variables; makes the example cleaner.