Fixed a bug in the add function