Neighborhood detection speedup. Things are still a bit messy and under-optimized.