Clean up the code a bit, yield file and filename instead of writing to disk