Refactoring in response to feedback on #5754.

Changes:
- More informative logging
- More informative error messages