Changing everything to a graph based structure instead of matrix