almost working delete function