Simplifying. TODO: Change output to string, then write string to file.