Updated with new temp file management.