Proper close handling