fix some bugs in remove functionaliy