cleaned up code for writing DOT, JSON