working summa algorithm