Lots of changes, mostly around handle errors.