Changed so it can handle when the index for the id in the marix is -1 because it is not in the matrix!!!!