Fixed a bug with the addAtIndex method