switch to BufferedStreams and clean up a little