Fixing deadlock problem