some bug fixes and new algorithm to loop through nearest neighbor cells