Fixing an index out of bounds error.