refactor some events logic