Improvements to add(ptr,val) and remove(ptr)