fixed bug in add function