Clean up tracking code, add some counters.