bug fixes for delete function