Minor refactoring to pull out the normalization function.