Some minor clean up, mostly to improve testability.