Fix crash in detach thread, remove old code.