re worked the event function so that it creates a dynamic function using the specified name