Fix  bug with end event firing in node when