Fix thread spawning issue and remove some dead code