edit function improved