Small improvement

The temp file is now deleted when an error occurs.