[f1]Code refactoring, adding file writing