Create addEvent function