improve three algorithms Oct 4th