fix / refactor event handling in backend.