Added close function to cancel timers and events.