Rewrite event tracking code to make it more DRY