improved code and output with png()