new version optimized for plotting