added error handling, switched to CURL