cleanup and better event handlers