Rewrite the event handler to use `match`

It now uses the event type to dispatch