Optimize getAdjacent code a bit