Fixed an index out of range bug