Tweak some algoritm steps and update tests.