Minor refactorings following the last commit for KMeans

Refactored the common function into a Functions util class. 
What's the chagne here, just whitespace?