Some improvements.

Hopefully the commit messages give enough context. Let me know if not.