Refactored calcAdjacencies to be more efficient