Bug fixes. Writing to file seems to work now.