Some refactorings and touch ups.