Modified thread loading to only use one query.