improve handling of closing