Refactored the stats panel code