Cleaned up threading code, part B