Fix deadlock problem