need to figure out how to make it so it doesn't create an tmpty file at the end