implement tempo, remove some global state