fixes for actually working in a multithreaded environment