made a couple of performance improvements, however it's still way too slow for random big graphs.