Performance improvement for unweighted graphs

Fixes #111