IndexOutOfRangeException occuring, needs fix