Fix some state memory issues.