use better way of handling temp file removal