fix close delay problem

please take a look at the commits.