A few improvements.
JGraphT included for extreme maths.