fixed the bug on the delete function