Merge Stas's fixes to restore old behavior in the chart function and