diff --git a/w2v-server.c b/w2v-server.c
new file mode 100644
index 0000000..f19443f
--- /dev/null
+++ b/w2v-server.c
@@ -0,0 +1,1141 @@
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <malloc.h>
+#include <stdlib.h>    //strlen
+#include <sys/mman.h>
+#include <pthread.h>
+#include <collocatordb.h>
+
+#define max_size 2000
+#define max_w 50
+#define MAX_NEIGHBOURS 1000
+#define MAX_WORDS -1
+#define MAX_THREADS 100
+#define MAX_CC 50
+#define EXP_TABLE_SIZE 1000
+#define MAX_EXP 6
+#define MIN_RESP 0.50
+
+//the thread function
+void *connection_handler(void *);
+
+typedef struct {
+	long long wordi;
+	long position;
+	float activation;
+	float average;
+	float cprobability; // column wise probability
+	float cprobability_sum;
+	float probability;
+	float activation_sum;
+	float max_activation;
+	float heat[16];
+} collocator;
+
+typedef struct {
+	collocator *best;
+	int length;
+} knn;
+  
+typedef struct {
+  long long wordi[MAX_NEIGHBOURS];
+  char sep[MAX_NEIGHBOURS];
+  int length;
+} wordlist;
+
+typedef struct {
+  long cutoff;
+  wordlist *wl;
+	char *token;
+	int N;
+	long from;
+	unsigned long upto;
+  collocator *best;
+  float *target_sums;
+  float *window_sums;
+  float threshold;
+} knnpars;
+
+typedef struct {
+  uint32_t index;
+  float value;
+} sparse_t;
+
+typedef struct {
+  uint32_t len;
+  sparse_t nbr[100];
+} profile_t;
+
+float *M, *M2=0L, *syn1neg_window, *expTable;
+float *window_sums;
+char *vocab;
+char *garbage = NULL;
+COLLOCATORDB *cdb = NULL;
+profile_t *sprofiles = NULL;
+size_t sprofiles_qty = 0;
+
+long long words, size, merged_end;
+long long merge_words = 0;
+int num_threads=20;
+int latin_enc=0;
+int window;
+
+/* load collocation profiles if file exists */
+int load_sprofiles(char *vecsname) {
+  char *basename = strdup(vecsname);
+  char *pos = strstr(basename, ".vecs");
+  if(pos)
+    *pos=0;
+  
+  char binsprofiles_fname[256];
+  strcpy(binsprofiles_fname, basename);
+	strcat(binsprofiles_fname, ".sprofiles.bin");
+  FILE *fp = fopen(binsprofiles_fname, "rb");
+  if (fp == NULL) {
+    printf("Collocation profiles %s not found. No problem.\n", binsprofiles_fname);
+    return 0;
+  }
+  fseek(fp, 0L, SEEK_END);
+  size_t sz = ftell(fp);
+  fclose(fp);
+
+  int fd = open(binsprofiles_fname, O_RDONLY);
+  sprofiles = mmap(0,  sz, PROT_READ, MAP_SHARED, fd, 0);
+  if (sprofiles == MAP_FAILED) {
+    close(fd);
+    fprintf(stderr, "Cannot mmap %s\n", binsprofiles_fname);
+    sprofiles = NULL;
+    return 0;
+  }  else {
+    sprofiles_qty = sz / sizeof(profile_t);
+    fprintf(stderr, "Successfully mmaped %s containing similar profiles for %ld word forms.\n", binsprofiles_fname, sprofiles_qty);
+  }
+  return 1;
+}
+
+int init_net(char *file_name, char *net_name, int latin) {
+  FILE *f, *binvecs, *binwords;
+	int binwords_fd, binvecs_fd, net_fd, i;
+	long long a, b, c, d, cn;
+	float len;
+  double val;
+
+	char binvecs_fname[256], binwords_fname[256];
+	strcpy(binwords_fname, file_name);
+	strcat(binwords_fname, ".words");
+	strcpy(binvecs_fname, file_name);
+	strcat(binvecs_fname, ".vecs");
+
+  latin_enc = latin;
+  f = fopen(file_name, "rb");
+  if (f == NULL) {
+    printf("Input file %s not found\n", file_name);
+    return -1;
+  }
+  fscanf(f, "%lld", &words);
+	if(MAX_WORDS > 0 && words > MAX_WORDS) words = MAX_WORDS;
+  fscanf(f, "%lld", &size);
+	if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) < 0  || (binwords_fd = open(binwords_fname, O_RDONLY)) < 0) {
+    printf("Converting %s to memory mappable structures\n", file_name);
+		vocab = (char *)malloc((long long)words * max_w * sizeof(char));
+		M = (float *)malloc((long long)words * (long long)size * sizeof(float));
+		if (M == NULL) {
+			printf("Cannot allocate memory: %lld MB    %lld  %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size);
+			return -1;
+		}
+    if(strstr(file_name, ".txt")) {
+      for (b = 0; b < words; b++) {
+        a = 0;
+        while (1) {
+          vocab[b * max_w + a] = fgetc(f);
+          if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
+          if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
+        }
+        vocab[b * max_w + a] = 0;
+        len = 0;
+        for (a = 0; a < size; a++) {
+          fscanf(f, "%lf", &val);
+          M[a + b * size] = val;
+          len += val * val;
+        } 
+        len = sqrt(len);
+        for (a = 0; a < size; a++) M[a + b * size] /= len;
+      }
+    } else {
+      for (b = 0; b < words; b++) {
+        a = 0;
+        while (1) {
+          vocab[b * max_w + a] = fgetc(f);
+          if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
+          if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
+        }
+        vocab[b * max_w + a] = 0;
+        fread(&M[b * size], sizeof(float), size, f);
+        len = 0;
+        for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size];
+        len = sqrt(len);
+        for (a = 0; a < size; a++) M[a + b * size] /= len;
+      }
+    }
+		if( (binvecs = fopen(binvecs_fname, "wb")) != NULL && (binwords = fopen(binwords_fname, "wb")) != NULL) {
+			fwrite(M, sizeof(float), (long long)words * (long long)size, binvecs);
+			fclose(binvecs);
+			fwrite(vocab, sizeof(char), (long long)words * max_w, binwords);
+			fclose(binwords);
+		}
+  }
+	if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) {
+		M = mmap(0, sizeof(float) * (long long)words * (long long)size, PROT_READ, MAP_SHARED, binvecs_fd, 0);
+		vocab = mmap(0,  sizeof(char) * (long long)words * max_w, PROT_READ, MAP_SHARED, binwords_fd, 0);
+    if (M == MAP_FAILED || vocab == MAP_FAILED) {
+			close(binvecs_fd);
+			close(binwords_fd);
+			fprintf(stderr, "Cannot mmap %s or %s\n", binwords_fname, binvecs_fname);
+			exit(-1);
+    }
+	} else {
+    fprintf(stderr, "Cannot open %s or %s\n", binwords_fname, binvecs_fname);
+    exit(-1);
+	}
+  fclose(f);
+
+  if(net_name && strlen(net_name) > 0) {
+    if( (net_fd = open(net_name, O_RDONLY)) >= 0) {
+      window = (lseek(net_fd, 0, SEEK_END) -  sizeof(float) * words * size) / words / size / sizeof(float) / 2;
+      //      lseek(net_fd, sizeof(float) * words * size, SEEK_SET);
+      // munmap(M,  sizeof(float) * words * size);
+      M2 = mmap(0, sizeof(float) * words * size + sizeof(float) * 2 * window * size * words, PROT_READ, MAP_SHARED, net_fd, 0);
+      if (M2 == MAP_FAILED) {
+        close(net_fd);
+        fprintf(stderr, "Cannot mmap %s\n", net_name);
+        exit(-1);
+      }
+      syn1neg_window =  M2 + words * size;
+    } else {
+      fprintf(stderr, "Cannot open %s\n", net_name);
+      exit(-1);
+    }
+    fprintf(stderr, "Successfully memmaped %s. Determined window size: %d\n", net_name, window);
+
+		char collocatordb_name[2048];
+		strcpy(collocatordb_name, net_name);
+		char *ext = rindex(collocatordb_name, '.');
+		if(ext) {
+			strcpy(ext, ".rocksdb");
+			if(access(collocatordb_name, R_OK) == 0) {
+				*ext = 0;
+				fprintf(stderr, "Opening collocator DB	%s\n", collocatordb_name);
+				cdb = open_collocatordb(collocatordb_name);
+			}
+		}
+	}
+
+	expTable = (float *) malloc((EXP_TABLE_SIZE + 1) * sizeof(float));
+	for (i = 0; i < EXP_TABLE_SIZE; i++) {
+		expTable[i] = exp((i / (float) EXP_TABLE_SIZE * 2 - 1) * MAX_EXP); // Precompute the exp() table
+		expTable[i] = expTable[i] / (expTable[i] + 1); // Precompute f(x) = x / (x + 1)
+	}
+	window_sums = malloc(sizeof(float) * (window+1) * 2);
+
+  return 0;
+}
+
+long mergeVectors(char *file_name){
+  FILE *f, *binvecs, *binwords;
+	int binwords_fd, binvecs_fd, net_fd, i;
+	long long a, b, c, d, cn;
+	float len;
+  float *merge_vecs;
+  char *merge_vocab;
+ /*  long long merge_words, merge_size; */
+  long long merge_size;
+
+	char binvecs_fname[256], binwords_fname[256];
+	strcpy(binwords_fname, file_name);
+	strcat(binwords_fname, ".words");
+	strcpy(binvecs_fname, file_name);
+	strcat(binvecs_fname, ".vecs");
+
+  f = fopen(file_name, "rb");
+  if (f == NULL) {
+    printf("Input file %s not found\n", file_name);
+    exit -1;
+  }
+  fscanf(f, "%lld", &merge_words);
+  fscanf(f, "%lld", &merge_size);
+  if(merge_size != size){
+		fprintf(stderr, "vectors must have the same length\n");
+		exit(-1);
+	}
+	if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) {
+		merge_vecs = malloc(sizeof(float) * (words + merge_words) * size);
+		merge_vocab = malloc(sizeof(char) * (words + merge_words) * max_w);
+    if (merge_vecs == NULL || merge_vocab == NULL) {
+			close(binvecs_fd);
+			close(binwords_fd);
+			fprintf(stderr, "Cannot reserve memory for %s or %s\n", binwords_fname, binvecs_fname);
+			exit(-1);
+    }
+    read(binvecs_fd, merge_vecs, merge_words * size * sizeof(float));
+    read(binwords_fd, merge_vocab, merge_words * max_w);
+	} else {
+    fprintf(stderr, "Cannot open %s or %s\n", binwords_fname, binvecs_fname);
+    exit(-1);
+	}
+	printf("Successfully reallocated memory\nMerging...\n");
+	fflush(stdout);
+  memcpy(merge_vecs + merge_words * size, M, words * size * sizeof(float));
+  memcpy(merge_vocab + merge_words * max_w, vocab, words * max_w);
+  munmap(M, words * size * sizeof(float));
+  munmap(vocab, words * max_w);
+  M = merge_vecs;
+  vocab = merge_vocab;
+  merged_end = merge_words;
+  words += merge_words;
+  fclose(f);
+	printf("merged_end: %lld, words: %lld\n", merged_end, words);
+	//printBiggestMergedDifferences();
+  return((long) merged_end);
+}
+
+void filter_garbage() {
+  long i;
+  unsigned char *w, previous, c;
+  garbage = malloc(words);
+  memset(garbage, 0, words);
+  for (i = 0; i < words; i++) {
+    w = vocab + i * max_w;
+    previous = 0;
+    if(strncmp("quot", w, 4) == 0) {
+      garbage[i]=1;
+//      printf("Gargabe: %s\n", vocab + i * max_w);
+    } else {
+      while((c = *w++) && !garbage[i]) {
+        if( ((c <= 90 && c >= 65) && (previous >= 97 && previous <= 122)) || 
+            (previous == '-' && (c & 32)) ||
+            (previous == 0xc2 && (c == 0xa4 || c == 0xb6 )) ||
+            (previous == 'q' && c == 'u' && *(w) == 'o' && *(w+1) == 't') || /* quot */
+            c == '<'
+          ) {
+          garbage[i]=1;
+          continue;
+        }
+        previous = c;
+      }
+    }
+  }
+  return;
+}
+
+  
+knn *simpleGetCollocators(int word, int number, long cutoff, int *result) {
+  knnpars *pars = calloc(sizeof(knnpars), 1);
+  float *target_sums;
+	float *window_sums = malloc(sizeof(float) * (window+1) * 2);
+  pars->cutoff = (cutoff? cutoff : 300000);
+	long a = posix_memalign((void **) &target_sums, 128, pars->cutoff * sizeof(float));
+  for(a = 0; a < cutoff; a++)
+    target_sums[a] = 0;
+  pars->target_sums = target_sums;
+  pars->window_sums = window_sums;
+  pars->N = (number? number : 20);
+  pars->from = 0;
+  pars->upto = window * 2 -1;
+  knn *syn_nbs = NULL; // = (knn*) getCollocators(pars);
+  free(pars);
+  free(window_sums);
+  free(target_sums);
+  return syn_nbs;
+}
+
+void *getCollocators(void *args) {
+  knnpars *pars = args;
+	int N = pars->N;
+
+  int cc = pars->wl->wordi[0];
+	knn *nbs = NULL;
+  long window_layer_size = size * window * 2;
+	long a, b, c, d, e, window_offset, target, max_target=0, maxmax_target;
+	float f, max_f, maxmax_f;
+	float *target_sums=NULL, worstbest, wpos_sum;
+	collocator *best;
+
+  if(M2 == NULL || cc == -1)
+    return NULL;
+
+	a = posix_memalign((void **) &target_sums, 128, pars->cutoff * sizeof(float));
+  memset(target_sums, 0, pars->cutoff * sizeof(float));
+	best = malloc((N>200?N:200) * sizeof(collocator));
+  memset(best, 0, (N>200?N:200) * sizeof(collocator));
+  worstbest = pars->threshold;
+
+  for (b = 0; b < pars->cutoff; b++)
+			target_sums[b]=0;
+  for (b = 0; b < N; b++) {
+      best[b].wordi = -1;
+      best[b].probability = 1;
+      best[b].activation = worstbest;
+  }
+
+  d = cc;
+  maxmax_f = -1;
+  maxmax_target = 0;
+
+  for (a = pars->from; a < pars->upto; a++) {
+    if(a >= window)
+      a++;
+    wpos_sum = 0;
+    printf("window pos: %ld\n", a);
+    if (a != window) {
+      max_f = -1;
+      window_offset = a * size;
+      if (a > window)
+        window_offset -= size;
+      for(target = 0; target < pars->cutoff; target ++) {
+				if(garbage && garbage[target]) continue;
+        if(target == d)
+          continue;
+        f = 0;
+        for (c = 0; c < size; c++)
+          f += M2[d* size + c]	* syn1neg_window[target * window_layer_size	+ window_offset + c];
+        if (f < -MAX_EXP)
+          continue;
+        else if (f > MAX_EXP)
+          continue;
+        else
+          f = expTable[(int) ((f + MAX_EXP)	* (EXP_TABLE_SIZE / MAX_EXP / 2))];
+        wpos_sum += f;
+
+        target_sums[target] += f;
+        if(f > worstbest) {
+          for (b = 0; b < N; b++) {
+            if (f > best[b].activation) {
+							memmove(best + b + 1, best + b, (N - b -1) * sizeof(collocator));
+							best[b].activation = f;
+							best[b].wordi = target;
+							best[b].position = window-a;
+							break;
+            }
+          }
+          if(b == N - 1)
+            worstbest = best[N-1].activation;
+        }
+      }
+      printf("%d %.2f\n", max_target, max_f);
+      printf("%s (%.2f) ", &vocab[max_target * max_w], max_f);
+      if(max_f > maxmax_f) {
+        maxmax_f = max_f;
+        maxmax_target = max_target;
+      }
+      for (b = 0; b < N; b++)
+        if(best[b].position == window-a)
+          best[b].cprobability = best[b].activation / wpos_sum;
+    } else {
+      printf("\x1b[1m%s\x1b[0m ", &vocab[d*max_w]);
+    }
+    pars->window_sums[a] = wpos_sum;
+  }
+  for (b = 0; b < pars->cutoff; b++)
+      pars->target_sums[b] += target_sums[b]; //(target_sums[b] / wpos_sum ) / (window * 2);
+
+  free(target_sums);
+  for(b=0; b<N && best[b].wordi >= 0; b++);; // THIS LOOP IS NEEDED (b...)
+//		printf("%d: best syn: %s %.2f %.5f\n", b, &vocab[best[b].wordi*max_w], best[b].activation, best[b].probability);
+//	printf("\n");
+  nbs = malloc(sizeof(knn));
+	nbs->best = best;
+	nbs->length = b-1;
+  pthread_exit(nbs);
+}
+
+
+AV *getVecs(AV *array) {
+  int i, b;
+  AV *result = newAV();
+  for (i=0; i<=av_len(array); i++) {
+    SV** elem = av_fetch(array, i, 0);
+    if (elem != NULL) {
+      long j = (long) SvNV(*elem);
+      AV *vector = newAV();
+      for (b = 0; b < size; b++) {
+        av_push(vector, newSVnv(M[b + j * size]));
+      }
+      av_push(result, newRV_noinc(vector));
+    }
+  }
+  return result;
+}
+
+char *getSimilarProfiles(long node) {
+  int i;
+  char buffer[120000];
+  char pair_buffer[2048];
+  buffer[0]='[';
+  buffer[1]=0;
+  if(node >= sprofiles_qty) {
+    printf("Not available in precomputed profile\n");
+    return(strdup("[{\"w\":\"not available\", \"v\":0}]\n"));
+  }
+
+  printf("******* %s ******\n", &vocab[max_w * node]);
+  
+  for(i=0; i < 100 && i < sprofiles[node].len; i++) {
+    sprintf(pair_buffer, "{\"w\":\"%s\", \"v\":%f},", &vocab[max_w * (sprofiles[node].nbr[i].index)], sprofiles[node].nbr[i].value);
+    strcat(buffer, pair_buffer);
+  }
+  buffer[strlen(buffer)-1]=']';
+  strcat(buffer, "\n");
+  printf(buffer);
+  return(strdup(buffer));
+}
+
+char *getClassicCollocators(long node) {
+	char *res = (cdb? strdup(get_collocators_as_json(cdb, node)) : "[]");
+	return res;
+}
+
+wordlist *getTargetWords(char *st1, int search_backw) {
+  wordlist *wl = malloc(sizeof(wordlist));
+  char st[100][max_size], sep[100];
+  long a, b=0, c=0, cn=0;
+  int unmerged;
+
+  while (1) {
+    st[cn][b] = st1[c];
+    b++;
+    c++;
+    st[cn][b] = 0;
+    if (st1[c] == 0) break;
+    if (st1[c] == ' ' || st1[c] == '-') {
+      sep[cn++] = st1[c];
+      b = 0;
+      c++;
+    }
+  }
+  cn++;
+  for (a = 0; a < cn; a++) {
+    if (search_backw) {
+      for (b = words - 1; b >= (merge_words? merge_words : 0) && strcmp(&vocab[b * max_w], st[a]) !=0; b--);
+    } else {
+      for (b = 0;     b < (merge_words? merge_words : words) && strcmp(&vocab[b * max_w], st[a]) != 0; b++);
+    }
+    if (b == words) b = -1;
+    wl->wordi[a] = b;
+    if (b == -1) {
+      fprintf(stderr, "Out of dictionary word!\n");
+      cn--;
+    } else {
+      fprintf(stderr, "Word: \"%s\"  Position in vocabulary: %lld\n", &vocab[wl->wordi[a]*max_w], wl->wordi[a]);
+    }
+  }
+  wl->length=cn;
+  return(wl);
+}
+
+float get_distance(long b, long c) {
+  long a;
+  float dist = 0;
+  for (a = 0; a < size; a++) dist += M[a + c * size] * M[a + b * size];
+  return dist;
+}
+
+char  *getBiggestMergedDifferences() {
+  static char *result = NULL;
+  float dist, len, vec[max_size];
+  long long a, b, c, d, cn, *bi;
+  char ch;
+  knn *nbs = NULL;
+  int N = 1000;
+
+  if(merged_end == 0)
+    result = "[]";
+    
+  if(result != NULL)
+    return result;
+
+  printf("Looking for biggest distances between main and merged vectors ...\n");
+  collocator *best;
+  best = malloc(N * sizeof(collocator));
+  memset(best, 0, N * sizeof(collocator));
+
+  float worstbest=1000000;
+
+  for (a = 0; a < N; a++) best[a].activation = worstbest;
+
+  for (c = 0; c < 500000; c++) {
+    if(garbage && garbage[c]) continue;
+    a = 0;
+    dist = 0;
+    for (a = 0; a < size; a++) dist += M[a + c * size] * M[a + (c+merged_end) * size];
+    if(dist < worstbest) {
+      for (a = 0; a < N; a++) {
+        if (dist < best[a].activation) {
+          memmove(best + a + 1, best + a, (N - a -1) * sizeof(collocator));
+          best[a].activation = dist;
+          best[a].wordi = c;
+          break;
+        }
+      }
+      worstbest = best[N-1].activation;
+    }
+  }
+
+  result = malloc(N*max_w);
+  char *p = result;
+  *p++ = '['; *p = 0;
+  for (a = 0; a < N; a++) {
+    p += sprintf(p, "{\"rank\":%d,\"word\":\"%s\",\"dist\":%.3f},", a, &vocab[best[a].wordi * max_w], 1-best[a].activation);
+  }
+  *--p = ']';
+  return(result);
+}
+
+
+float cos_similarity(long b, long c) {
+  float dist=0;
+  long a;
+ 	for (a = 0; a < size; a++) dist += M[b * size + a] * M[c * size + a];
+  return dist;
+}
+
+char *cos_similarity_as_json(char *w1, char *w2) {
+  wordlist *a, *b;
+  float res;
+  a = getTargetWords(w1, 0);
+  b = getTargetWords(w2, 0);
+  if (a == NULL || b==NULL || a->length != 1 || b->length != 1)
+    res = -1;
+  else
+    res = cos_similarity(a->wordi[0], b->wordi[0]);
+  fprintf(stderr, "a: %lld b: %lld res:%f\n", a->wordi[0], b->wordi[0], res);
+  char *json = malloc(16);
+  sprintf(json, "%.5f", res);
+  return json;
+}
+
+void *_get_neighbours(void *arg) {
+  knnpars *pars = arg;
+	char *st1 = pars->token;
+	int N = pars->N;
+	long from = pars -> from;
+	unsigned long upto = pars -> upto;
+	char file_name[max_size], st[100][max_size], *sep;
+	float dist, len, vec[max_size];
+	long long a, b, c, d, cn, *bi;
+	char ch;
+	knn *nbs = NULL;
+  wordlist *wl = pars->wl;
+  
+	collocator *best = pars->best;
+
+	float worstbest=-1;
+
+	for (a = 0; a < N; a++) best[a].activation = 0;
+	a = 0;
+  bi = wl->wordi;
+	cn = wl->length;
+  sep = wl->sep;
+	b = bi[0];
+	c = 0;
+	if (b == -1) {
+    N = 0;
+	  goto end;
+  }
+	for (a = 0; a < size; a++) vec[a] = 0;
+	for (b = 0; b < cn; b++) {
+		if (bi[b] == -1) continue;
+    if(b>0 && sep[b-1] == '-')
+      for (a = 0; a < size; a++) vec[a] -= M[a + bi[b] * size];
+    else
+      for (a = 0; a < size; a++) vec[a] += M[a + bi[b] * size];
+	}
+	len = 0;
+	for (a = 0; a < size; a++) len += vec[a] * vec[a];
+	len = sqrt(len);
+	for (a = 0; a < size; a++) vec[a] /= len;
+	for (a = 0; a < N; a++) best[a].activation = -1;
+	for (c = from; c < upto; c++) {
+    if(garbage && garbage[c]) continue;
+		a = 0;
+// do not skip taget word
+//		for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
+//		if (a == 1) continue;
+		dist = 0;
+		for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size];
+		if(dist > worstbest) {
+			for (a = 0; a < N; a++) {
+				if (dist > best[a].activation) {
+					memmove(best + a + 1, best + a, (N - a -1) * sizeof(collocator));
+					best[a].activation = dist;
+					best[a].wordi = c;
+					break;
+				}
+			}
+			worstbest = best[N-1].activation;
+		}
+	}
+
+end:
+	pthread_exit(nbs);
+}
+
+int cmp_activation (const void * a, const void * b) {
+   float fb = ((collocator *)a)->activation;
+   float fa = ((collocator *)b)->activation;
+   return (fa > fb) - (fa < fb);
+}
+
+int cmp_probability (const void * a, const void * b) {
+   float fb = ((collocator *)a)->probability;
+   float fa = ((collocator *)b)->probability;
+   return (fa > fb) - (fa < fb);
+}
+
+char* getPosWiseW2VCollocatorsAsTsv(char *word, long maxPerPos, long cutoff, float threshold) {
+    HV *result = newHV();
+	float *target_sums=NULL, vec[max_size];
+	long long old_words;
+	long a, b, c, d;
+	knn *para_nbs[MAX_THREADS];
+	knn *syn_nbs[MAX_THREADS];
+	knnpars pars[MAX_THREADS];
+  pthread_t *pt = (pthread_t *)malloc((num_threads+1) * sizeof(pthread_t));
+  wordlist *wl;
+  int syn_threads = (M2? window * 2 : 0);
+  int search_backw = 0;
+  collocator *best = NULL;
+  posix_memalign((void **) &best, 128, 10 * (maxPerPos>=200? maxPerPos : 200)  * sizeof(collocator));
+  memset(best, 0, (maxPerPos>=200? maxPerPos : 200) * sizeof(collocator));
+
+
+  if(cutoff < 1 || cutoff > words)
+    cutoff=words;
+
+  wl = getTargetWords(word, search_backw);
+  if(wl == NULL || wl->length < 1)
+    return "";
+
+	a = posix_memalign((void **) &target_sums, 128, cutoff * sizeof(float));
+  memset(target_sums, 0, cutoff * sizeof(float));
+
+  printf("Starting %d threads\n", syn_threads);
+  fflush(stdout);
+  for(a=0; a < syn_threads; a++) {
+			pars[a].cutoff = cutoff;
+      pars[a].target_sums = target_sums;
+      pars[a].window_sums = window_sums;
+      pars[a].wl = wl;
+      pars[a].N = maxPerPos;
+      pars[a].threshold = threshold;
+      pars[a].from = a;
+      pars[a].upto = a+1;
+      pthread_create(&pt[a], NULL, getCollocators, (void *) &pars[a]);
+  }
+  printf("Waiting for syn threads to join\n");
+  fflush(stdout);
+  for (a = 0; a < syn_threads; a++) pthread_join(pt[a], (void *) &syn_nbs[a]);
+  printf("Syn threads joint\n");
+  fflush(stdout);
+  result = malloc(maxPerPos*80*syn_threads);
+  char *p = result;
+  *p = 0;
+	for (a = syn_threads -1; a >= 0; a--) {
+    for (b=0; b < syn_nbs[a]->length; b++) {
+      p += sprintf(p, "%ld\t%s\t%f\n", syn_nbs[a]->best[b].position, &vocab[syn_nbs[a]->best[b].wordi * max_w], syn_nbs[a]->best[b].activation);
+    }
+	}
+  return(result);
+}
+
+SV *get_neighbours(char *st1, int N, int sort_by, int search_backw, long cutoff, int dedupe, int no_similar_profiles) {
+  HV *result = newHV();
+	float *target_sums=NULL, vec[max_size];
+	long long old_words;
+	long a, b, c, d, slice;
+	knn *para_nbs[MAX_THREADS];
+	knn *syn_nbs[MAX_THREADS];
+	knnpars pars[MAX_THREADS];
+  pthread_t *pt = (pthread_t *)malloc((num_threads+1) * sizeof(pthread_t));
+  wordlist *wl;
+  int syn_threads = (M2? window * 2 : 0);
+  int para_threads = (no_similar_profiles? 0 : num_threads - syn_threads);
+
+  collocator *best = NULL;
+  posix_memalign((void **) &best, 128, 10 * (N>=200? N : 200)  * sizeof(collocator));
+  memset(best, 0, (N>=200? N : 200) * sizeof(collocator));
+
+  if(N>MAX_NEIGHBOURS) N=MAX_NEIGHBOURS;
+	
+  if(cutoff < 1 || cutoff > words)
+    cutoff=words;
+
+  wl = getTargetWords(st1, search_backw);
+  if(wl == NULL || wl->length < 1)
+    goto end;
+
+	old_words = cutoff;
+	slice = cutoff / para_threads;
+
+	a = posix_memalign((void **) &target_sums, 128, cutoff * sizeof(float));
+  memset(target_sums, 0, cutoff * sizeof(float));
+
+  printf("Starting %d threads\n", para_threads);
+  fflush(stdout);
+	for(a=0; a < para_threads; a++) {
+		pars[a].cutoff = cutoff;
+		pars[a].token = st1;
+		pars[a].wl = wl;
+		pars[a].N = N;
+    pars[a].best = &best[N*a];
+    if(merge_words == 0 || search_backw == 0) {
+      pars[a].from = a*slice;
+      pars[a].upto = ((a+1)*slice > cutoff? cutoff : (a+1) * slice);
+    } else {
+      pars[a].from = merge_words + a * slice;
+      pars[a].upto = merge_words + ((a+1)*slice > cutoff? cutoff : (a+1) * slice);
+    }
+    printf("From: %ld, Upto: %ld\n",  pars[a].from, pars[a].upto);
+		pthread_create(&pt[a], NULL, _get_neighbours, (void *) &pars[a]);
+	}
+  if(M2) {
+    for(a=0; a < syn_threads; a++) {
+			pars[a + para_threads].cutoff = cutoff;
+      pars[a + para_threads].target_sums = target_sums;
+      pars[a + para_threads].window_sums = window_sums;
+      pars[a + para_threads].wl = wl;
+      pars[a + para_threads].N = N;
+      pars[a + para_threads].threshold = MIN_RESP;
+      pars[a + para_threads].from = a;
+      pars[a + para_threads].upto = a+1;
+      pthread_create(&pt[a + para_threads], NULL, getCollocators, (void *) &pars[a + para_threads]);
+    }
+  }
+  printf("Waiting for para threads to join\n");
+  fflush(stdout);
+  for (a = 0; a < para_threads; a++) pthread_join(pt[a], (void *) &para_nbs[a]);
+  printf("Para threads joint\n");
+  fflush(stdout);
+
+	/* if(!syn_nbs[0]) */
+	/* 	goto end; */
+
+  qsort(best, N*para_threads, sizeof(collocator), cmp_activation);
+
+
+  long long chosen[MAX_NEIGHBOURS];
+  printf("N: %ld\n", N);
+
+  AV* array = newAV();
+  int i, j;
+  int l1_words=0, l2_words=0;
+ 
+  for (a = 0, i = 0; i < N && a < N*para_threads; a++) {
+    int filtered=0;
+    long long c = best[a].wordi;
+    if ((merge_words && dedupe && i > 1) || (!merge_words && dedupe && i > 0)) {
+      for (j=0; j<i && !filtered; j++)
+        if (strcasestr(&vocab[c * max_w], &vocab[chosen[j] * max_w]) ||
+            strcasestr(&vocab[chosen[j] * max_w], &vocab[c * max_w])) {
+              printf("filtering %s %s\n", &vocab[chosen[j] * max_w], &vocab[c * max_w]);
+              filtered = 1;
+        }
+      if(filtered)
+        continue;
+    }
+
+
+    if(0 && merge_words > 0) {
+        if(c >= merge_words) {
+            if(l1_words > N / 2)
+                continue;
+            else
+                l1_words++;
+        } else {
+            if(l2_words > N / 2)
+                continue;
+            else
+                l2_words++;
+        }
+    }
+
+//    printf("%s l1:%d l2:%d i:%d a:%ld\n", &vocab[c * max_w], l1_words, l2_words, i, a);
+//    fflush(stdout);
+    HV* hash = newHV();
+    SV* word = newSVpvf(&vocab[c * max_w], 0);
+		chosen[i] = c;
+    if(latin_enc == 0) SvUTF8_on(word);
+    fflush(stdout);
+    hv_store(hash, "word", strlen("word"), word , 0);
+    hv_store(hash, "dist", strlen("dist"), newSVnv(best[a].activation), 0);
+    hv_store(hash, "rank", strlen("rank"), newSVuv(best[a].wordi), 0);
+    AV *vector = newAV();
+    for (b = 0; b < size; b++) {
+      av_push(vector, newSVnv(M[b + best[a].wordi * size]));
+    }
+    hv_store(hash, "vector", strlen("vector"), newRV_noinc((SV*)vector), 0);
+    av_push(array, newRV_noinc((SV*)hash));
+    i++;
+  }
+  hv_store(result, "paradigmatic", strlen("paradigmatic"), newRV_noinc((SV*)array), 0);
+
+  for(b=0; b < MAX_NEIGHBOURS; b++) {
+    best[b].wordi = -1L;
+    best[b].activation = 0;
+    best[b].probability = 0;
+    best[b].position = 0;
+    best[b].activation_sum = 0;
+    memset(best[b].heat, 0, sizeof(float)*16);
+  }
+
+	float total_activation = 0;
+
+  if (M2) {
+    printf("Waiting for syn threads to join\n");
+    fflush(stdout);
+    for (a = 0; a < syn_threads; a++) pthread_join(pt[a+para_threads], (void *) &syn_nbs[a]);
+		for (a = 0; a <= syn_threads; a++) {
+      if(a == window) continue;
+			total_activation += window_sums[a];
+			printf("window pos: %d, sum: %f\n", a, window_sums[a]);
+		}
+    printf("syn threads joint\n");
+    fflush(stdout);
+
+    for(b=0; b < syn_nbs[0]->length; b++) {
+			memcpy(best + b, &syn_nbs[0]->best[b], sizeof(collocator));
+      best[b].position = -1; //  syn_nbs[0]->pos[b];
+      best[b].activation_sum = target_sums[syn_nbs[0]->best[b].wordi];
+			best[b].max_activation = 0.0;
+			best[b].average = 0.0;
+			best[b].probability = 0.0;
+			best[b].cprobability = syn_nbs[0]->best[b].cprobability;
+			memset(best[b].heat, 0, sizeof(float)*16);
+    }
+		
+		float best_window_sum[MAX_NEIGHBOURS];
+    int found_index=0, i=0, j, w;
+    for(a=0; a < syn_threads; a++) {
+      for(b=0; b < syn_nbs[a]->length; b++) {
+				for(i=0; i < found_index; i++)
+					if(best[i].wordi == syn_nbs[a]->best[b].wordi)
+						break;
+				if(i >= found_index) {
+					best[found_index].max_activation = 0.0;
+					best[found_index].average = 0.0;
+					best[found_index].probability = 0.0;
+					memset(best[found_index].heat, 0, sizeof(float)*16);
+					best[found_index].cprobability = syn_nbs[a]->best[b].cprobability;
+					best[found_index].activation_sum = target_sums[syn_nbs[a]->best[b].wordi]; // syn_nbs[a]->best[b].activation_sum;
+					best[found_index++].wordi = syn_nbs[a]->best[b].wordi;
+					//						printf("found: %s\n", &vocab[syn_nbs[a]->index[b] * max_w]);
+				}
+			}
+		}
+		sort_by =0; // ALWAYS AUTO-FOCUS
+    if(sort_by != 1 && sort_by != 2) { // sort by auto focus mean
+			printf("window: %d  -  syn_threads: %d, %d\n", window, syn_threads, (1 << syn_threads) -1);
+			int wpos;
+      int bits_set = 0;
+			for(i=0; i < found_index; i++) {
+				best[i].activation = best[i].probability = best[i].average = best[i].cprobability_sum = 0;
+				for(w=1; w <  (1 << syn_threads); w++) { // loop through all possible windows
+					float word_window_sum = 0, word_window_average=0, word_cprobability_sum=0, word_activation_sum = 0, total_window_sum = 0;
+          bits_set = 0;
+					for(a=0; a < syn_threads; a++) {
+						if((1 << a) & w) {
+							wpos = (a >= window? a+1 : a);
+							total_window_sum += window_sums[wpos];
+						}
+					}
+//					printf("%d window-sum %f\n", w, total_window_sum);
+					for(a=0; a < syn_threads; a++) {
+						if((1 << a) & w) {
+							wpos = (a >= window? a+1 : a);
+ 						  bits_set++;
+						  for(b=0; b < syn_nbs[a]->length; b++)
+							  if(best[i].wordi == syn_nbs[a]->best[b].wordi) {
+//									float acti = syn_nbs[a]->best[b].activation / total_window_sum;
+//                  word_window_sum += syn_nbs[a]->dist[b] *  syn_nbs[a]->norm[b]; // / window_sums[wpos];  // syn_nbs[a]->norm[b];
+//                    word_window_sum += syn_nbs[a]->norm[b]; // / window_sums[wpos];  // syn_nbs[a]->norm[b];
+//                  word_window_sum = (word_window_sum + syn_nbs[a]->norm[b]) - (word_window_sum * syn_nbs[a]->norm[b]);  // syn_nbs[a]->norm[b];
+
+                  word_window_sum += syn_nbs[a]->best[b].activation; // / window_sums[wpos];  // syn_nbs[a]->norm[b];
+//                  word_window_sum += acti - (word_window_sum * acti); syn_nbs[a]->best[b].activation; // / window_sums[wpos];  // syn_nbs[a]->norm[b];
+
+                  word_window_average += syn_nbs[a]->best[b].activation; // - word_window_average * syn_nbs[a]->best[b].activation;  // conormalied activation sum
+                  word_cprobability_sum += syn_nbs[a]->best[b].cprobability - word_cprobability_sum * syn_nbs[a]->best[b].cprobability;  // conormalied column probability sum
+									word_activation_sum += syn_nbs[a]->best[b].activation;
+                  if(syn_nbs[a]->best[b].activation > best[i].max_activation)
+										best[i].max_activation = syn_nbs[a]->best[b].activation;
+                  if(syn_nbs[a]->best[b].activation > best[i].heat[wpos] )
+										best[i].heat[wpos] = syn_nbs[a]->best[b].activation;
+								}
+						}
+					}
+          if(bits_set) {
+            word_window_average /= bits_set;
+//						word_activation_sum /= bits_set;
+//						word_window_sum /= bits_set;
+          }
+
+					word_window_sum /= total_window_sum;
+
+          if(word_window_sum > best[i].probability) {
+//						best[i].position = w;
+						best[i].probability = word_window_sum;
+					}
+
+          if(word_cprobability_sum > best[i].cprobability_sum) {
+						best[i].position = w;
+						best[i].cprobability_sum = word_cprobability_sum;
+					}
+
+						best[i].average = word_window_average;
+//						best[i].activation = word_activation_sum;
+        }
+			}
+			qsort(best, found_index, sizeof(collocator), cmp_probability);
+//      for(i=0; i < found_index; i++) {
+//				printf("found: %s - sum: %f - window: %d\n", &vocab[best[i].wordi * max_w], best[i].activation, best[i].position);
+//			}
+
+    } else if(sort_by == 1) { // responsiveness any window position
+			int wpos;
+			for(i=0; i < found_index; i++) {
+ 					float word_window_sum = 0, word_activation_sum = 0, total_window_sum = 0;
+					for(a=0; a < syn_threads; a++) {
+							wpos = (a >= window? a+1 : a);
+						  for(b=0; b < syn_nbs[a]->length; b++)
+							  if(best[i].wordi == syn_nbs[a]->best[b].wordi) {
+                  best[i].probability += syn_nbs[a]->best[b].probability;
+									if(syn_nbs[a]->best[b].activation > 0.25)
+									  best[i].position |= 1 << wpos;
+									if(syn_nbs[a]->best[b].activation > best[i].activation) {
+										best[i].activation = syn_nbs[a]->best[b].activation;
+                  }
+								}
+					}
+			}
+			qsort(best, found_index, sizeof(collocator), cmp_activation);
+     } else if(sort_by == 2) { // single window position
+       for(a=1; a < syn_threads; a++) {
+        for(b=0; b < syn_nbs[a]->length; b++) {
+          for(c=0; c < MAX_NEIGHBOURS; c++) {
+            if(syn_nbs[a]->best[b].activation > best[c].activation) {
+              for(d=MAX_NEIGHBOURS-1; d>c; d--) {
+								memmove(best + d, best + d - 1, sizeof(collocator));
+              }
+              memcpy(best + c, &syn_nbs[a]->best[b], sizeof(collocator));
+              best[c].position = 1 << (-syn_nbs[a]->best[b].position+window - (syn_nbs[a]->best[b].position < 0 ? 1:0));
+              break;
+            }
+          }
+        }
+      }
+    } else { // sort by mean p
+      for(a=1; a < syn_threads; a++) {
+        for(b=0; b < syn_nbs[a]->length; b++) {
+          for(c=0; c < MAX_NEIGHBOURS; c++) {
+            if(target_sums[syn_nbs[a]->best[b].wordi] > best[c].activation_sum) {
+              for(d=MAX_NEIGHBOURS-1; d>c; d--) {
+								memmove(best + d, best + d - 1, sizeof(collocator));
+              }
+              memcpy(best + c, &syn_nbs[a]->best[b], sizeof(collocator));
+              best[c].position = (1 << 2*window) - 1; // syn_nbs[a]->pos[b];
+              best[c].activation_sum = target_sums[syn_nbs[a]->best[b].wordi];
+              break;
+            }
+          }
+        }
+      }
+    }
+    array = newAV();
+    for (a = 0, i=0; a < MAX_NEIGHBOURS && best[a].wordi >= 0; a++) {
+      long long c = best[a].wordi;
+/*
+      if (dedupe) {
+	  		int filtered=0;
+        for (j=0; j<i; j++)
+          if (strcasestr(&vocab[c * max_w], chosen[j]) ||
+              strcasestr(chosen[j], &vocab[c * max_w])) {
+						printf("filtering %s %s\n", chosen[j], &vocab[c * max_w]);
+						filtered = 1;
+					}
+				if(filtered)
+					continue;
+			}
+*/
+			chosen[i++]=c;
+      HV* hash = newHV();
+      SV* word = newSVpvf(&vocab[best[a].wordi * max_w], 0);
+      AV* heat = newAV();
+      if(latin_enc == 0) SvUTF8_on(word);
+      hv_store(hash, "word", strlen("word"), word , 0);
+      hv_store(hash, "rank", strlen("rank"), newSVuv(best[a].wordi), 0);
+      hv_store(hash, "average", strlen("average"), newSVnv(best[a].average), 0);
+      hv_store(hash, "prob", strlen("prob"), newSVnv(best[a].probability), 0);
+      hv_store(hash, "cprob", strlen("cprob"), newSVnv(best[a].cprobability_sum), 0);
+      hv_store(hash, "max", strlen("max"), newSVnv(best[a].max_activation), 0); // newSVnv(target_sums[best[a].wordi]), 0);
+      hv_store(hash, "overall", strlen("overall"), newSVnv(best[a].activation_sum/total_activation), 0); // newSVnv(target_sums[best[a].wordi]), 0);
+      hv_store(hash, "pos", strlen("pos"), newSVnv(best[a].position), 0);
+      best[a].heat[5]=0;
+      for(i=10; i >= 0; i--) av_push(heat, newSVnv(best[a].heat[i]));
+      hv_store(hash, "heat", strlen("heat"), newRV_noinc((SV*)heat), 0);
+      av_push(array, newRV_noinc((SV*)hash));
+    }
+    hv_store(result, "syntagmatic", strlen("syntagmatic"), newRV_noinc((SV*)array), 0);
+  }
+end:
+  //  words = old_words; // why was this here?
+	free(best);
+	return newRV_noinc((SV*)result);
+}
+
+int dump_vecs(char *fname) {
+	long i, j;
+	FILE *f;
+/*  if(words>100000)
+	 	words=100000;
+*/
+	if((f=fopen(fname, "w")) == NULL) {
+			fprintf(stderr, "cannot open %s for writing\n", fname);
+			return(-1);
+	}
+	fprintf(f, "%lld %lld\n", words, size);
+	for (i=0; i < words; i++) {
+		fprintf(f, "%s ", &vocab[i * max_w]);
+		for(j=0; j < size - 1; j++)
+			fprintf(f, "%f ", M[i*size + j]);
+		fprintf(f, "%f\n", M[i*size + j]);
+	}
+	fclose(f);
+	return(0);
+}
+
+int dump_for_numpy(char *fname) {
+	long i, j;
+	FILE *f;
+  int max = 300000;
+
+	if((f=fopen(fname, "w")) == NULL) {
+			fprintf(stderr, "cannot open %s for writing\n", fname);
+			return(-1);
+	}
+	for (i=0; i < max; i++) {
+		for(j=0; j < size - 1; j++)
+			fprintf(f, "%f\t", M[i*size + j]);
+		fprintf(f, "%f\n", M[i*size + j]);
+		printf("%s\r\n", &vocab[i * max_w]);
+  }
+  if(merged_end > 0) {
+    for (i=0; i < max; i++) {
+      for(j=0; j < size - 1; j++)
+        fprintf(f, "%f\t", M[(merged_end + i)*size + j]);
+      fprintf(f, "%f\n", M[(merged_end + i)*size + j]);
+      printf("_%s\r\n", &vocab[i * max_w]);
+    }
+	}
+	fclose(f);
+ 	return(0);
+}
