Fixed deadlock issues