Improve tracking code, clean up a bit