still crashing, but fixed bug in thread switch