Code tidy-ups

- add doc comments
- move a couple of methods to be free functions
- fix warnings
  - drop unused imports
  - drop unnecessary parentheses
  - drop unneeded `mut`
  - drop unused variables
  - `unwrap` results in tests
- error messages
  - include original error where possible
  - more consistent & terser wording
  - consistent leading lowercase letter in error messages
- typos
- comment reflow

Bug: 197891150
Bug: 239476605
Test: build
Change-Id: I53de09af7de23027c9ec7d4ab8e6f610c2cadc3c
10 files changed