Fixed most of the threading