Fixed race condition in removing connection