uncomment networkx import and fix KDTree usage