I've updated the file writing process to be more efficient