Fixed up some tempfile problems with this script