refactored API code into its own class