fixed the neighbor state calculations