Delete function improved