better error handling for events