major refactoring, threading bugfixes