improved event logic