Tidied up a bit and made a bit more pythonic

Can't test this as I don't have the same graph data available