fixed bugs for add and remove operations