First round of optimization....

And a state-change event handler.