Reorded isAdjacent function slightly