Lots of changes, mostly in error handling