optimize UI event handler