Minor changes to callback functions, so that error handling is central.