add file writing part of the function