General bug fixes

Fixes for  event and timeout leaks.