code refinning for producing graph