Revamp the file creation code