factorize the graph paper code