clean up the endThreadIfAllLoaded function