Thread bugfixes