Completely re-did on_* handling. Actually makes some sense now and seems
to work.