refactored eventing: separated event handlers, refactored misc code