Cleaned up exportStats() function