More robust history length control