Refactored to match latest versions of api