fixing various issues, improving error reporting