finalising kmeans code