Fixed bug in plot data formatting function