refactoring user stats code