Changed plotting function slightly