bunch of cleanups, hopefully fixed deadlock