Improved error handling for k-means clustering.