Fixes for bug in parallel kmeans. Also refactored parallel code.