Minor refactorings following the last commit for KMeans

Refactored the common function into a Functions util class. 
Shouldn't have to duplicate this now right?