Updated statistics function to run in background.