Refactored API code into its own class