added error handling to events