Fixed deadlock problems