updated so you don't have to use the tempfile if you don't want to