added error handling to ajax calls