Add tests.

- Minor fixes resulting from testing.
- Be more pythonic here & there.
[cosmetic] Remove trailing whitespace.