Added better error handling and a CRS to the shapefile export.