lots of fixes to error handling etc