Minor refactorings following the last commit for KMeans

Refactored the common function into a Functions util class. 
Done