Fixed deadlock bug