Writing a functionListening for an event