fix a threading issue with client closing
Optimize context wait behavior (all but last)