Implemented Tony's modification to use data stream instead of temp file.