fixes index bounds checking in add()