Anonymous functions and use of global variables to code a timer