Fixed some bugs, added the assert on graph construction