Fix bugs in deleting tree