make Endgmae global out of thread