add events and optimal code