Event: separate logic between main loop and backend

Signed-off-by: Eduardo Silva <eduardo@monkey.io>