Added database functionality to store stats