Merge two thread patches from cloudbot-slay-the-beast