corrected graph generating code