Minor refactorings following the last commit for KMeans

Refactored the common function into a Functions util class. 
I might have to rename that to something other than 'Functions'. There is already a lambda.Functions and for some reason IntelliJ is having a hard time in picking the right one.