Refactoring code that accesses external services

Refactoring some code so that the lines that call and unpack data from an external service are separated into clear objects.