Creating an event-driven Function