added close handling