improved error handling etc