Minor improvements to the stem fitting algorithm