new way of outputting the file, much cleaner