Miscellaneous additions and refactoring

I am a Rust rookie.
Not many tests.
The most controversial change is 2a8ee6a.