add event handler & fix some bugs