Adding error handling around each event