Minor refactorings following the last commit for KMeans

Refactored the common function into a Functions util class. 
This still needs to be removed.