Minor refactoring and clean ups.
More minor fixes