improving duplicate events algorithm and better output