incorporated the previously mentioned functions into the main writefile function
changed headers. Need to fix bug with file format