move onstatechange callback addition back outside init, and fix typo