Some small improvements to the core algorithm.