improved the delete fucntion