add safe_close()
add remove_handler() after handle_error()