refactor events system