Refactored out the initialization of the api