updated the graph and wrapped in function for easy reuse