Initial checkin of KMeans implementation

Basic framework for KMeans implementation and code refactoring.
my bad, didn't really read the code before refactoring. I think this should go back into ALSUpdate ??