Enable write to multiple files
Refactor code