Fixing memory limit and adding NN counting