error checking for curl thanks to @dpiddy