Fix event and error handling