first version, use global variable to keep track of time