changes on looping through adjacency matrix