fix a couple of bugs

First there was a memory leak.  Second, after running export, there was the possiblity of the wrong files being read in for a subsequent read.  This happens because export changes the working directory.  Now we make sure read also sets the current directory.