refactored square_sum method