small improvements to algo