Fixed deadlock situation in some cases