Fixed the update whereclause and added more error handling.