Fix bugs in delete