w2v-server: fix segmentation faults
diff --git a/w2v-server.pl b/w2v-server.pl
index 1cddc86..fa8e652 100644
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -224,7 +224,8 @@
   maxmax_f = -1;
   maxmax_target = 0;
 
-
+  if(cc == -1)
+    return NULL;
   for (a = window * 2 + 1; a >=0; a--) {
     printf("window pos: %ld\n", a);
     if (a != window) {
@@ -286,7 +287,7 @@
   printf(" -- max sum: %s (%.2f), max resp.: \x1b[1m%s\x1b[0m (%.2f)\n",
          &vocab[max_target * max_w], max_f,
          &vocab[maxmax_target * max_w], maxmax_f);
-  for(b=0; b<N && bestf[b]>-1; b++) 
+  for(b=0; b<N && bestf[b]>0.2; b++) 
     printf("%-32s %.2f %d\n", &vocab[besti[b]*max_w], bestf[b], bestp[b]);
   printf("\n");
 	free(target_sums);
@@ -294,7 +295,7 @@
 	nbs->index = besti;
 	nbs->dist = bestf;
 	nbs->pos = bestp;
-	nbs->length = N;
+	nbs->length = b;
   return(nbs);
 }
 
@@ -497,7 +498,7 @@
       bestp[b] = nbs[num_threads]->pos[b];
     }
     array = newAV();
-		for (a = 0; a < 10; a++) {
+		for (a = 0; a < nbs[num_threads]->length; a++) {
 			strcpy(bestw[a], &vocab[besti[a] * max_w]);
 			HV* hash = newHV();
       SV* word = newSVpvf(bestw[a], 0);