refactor _handle_btn_close and avoid dom memory leak