Fix possible deadlock