Added Licence
Improved logic and fixed a stupid bug on graph size