Updated and fixed the delete function