Fixed two IndexOutOfRangeException issues.