more checks to file creation, added implicit header writing