Fixed possible deadlock