Minor fixups

The following commits are trivial, mostly clean ups and refactoring.