[cvs-nhc98] Refactor hat-detect: use named fields in the state instea