More threading code moved over.