added error handling and json encoding to thurgood calls