refactored sum_square_digits method