minor fixes, some new error handling.