changed an onended function
rewrite