Code to record stats