Added convenience funciton to write files directly.