polished the event handlers on the Python side.