rewrite code according to fragment

I have rewritten event part