Please propagate this to the release branch. svn: r17756
tweaked error selection algorithm added tests svn: r16533
svn: r16098