fixed the neighbor calculation