General code and event handler cleanup