refactor event managing