More bug fixes in neighbor list construction. Added option to return distances.