made file-writing system more modular