moved same_cell control outside the neighbor funciton