Cleaned up threading code, part C; this is last major overhaul of the threading code for now, smaller changes will be made as needed in the future