fix close handling