refactored writing in dot file