How to reset timer if state changes?