First pass at porting kmeans from numberoverzero/kmeans