called clearState() to factor out some field reassigning.