Improve delete function