improve delete function