WIP: fix a bug in ComputekNNPosteriors function
WIP: fix some segfault bugs