properly sort blocks in graph