Refactored calcAdjacencies as per Professor Rader's suggestions