add event loop on flat tree
improved event loop