Additional error handling and fixes from code review.

(integrated from master branch change 0df508b by cgchoffman <cgchoffman@gmail.com>)