Fixed possible deadlock issue