Event management.

This is a major restructuration.
Most of the commands code is replicated and adapted to events.