Minor fixes to algorithms that were totally wrong