Implemented correct close handling