Minor improvements

The improvements:
1) An error will be raised when topsort() detects cycles.
2) Using a local var.
3) Don't require qtsvg when saving to a file.