added graph visualization, fixed some bug in the functions