Fix tests and add stats tracking