updated group ans squaring algo with working tests