minor fixes, improved error handling