Changed the end event (to avoid race conditions)