Updated to use temporary files.