cleaned code for preprocessing of graphs