add event generator & rafactor code