Fixed deadlock; got rid of global lock