Fixed array out of bounds exception in Graph