Fix detached head corruption