Added a change to add(int, Object) to check the index range.