Code refactored. Now outputs DOT files as well.