Fixed a possible deadlock scenario