Updated add() to accept index parameter.