bug fixes, improved error messages