resolved sorting problem by using the graph instead of comparable