Improved functionality for add() function.