DRYed up the API code itself