fix leak with files not cleaning up correctly