Fix history rewriting