Stricter with types

This PR suggests using stricter typedef's, and being stricter with types on a number of places.

Thanks for any review. (This PR doesn't include functional changes, so I'll merge it even if it isn't reviewed.)