fix bugs for delete function