Properly initializing the API

This wasn't a problem because the API was being initialized by something else first but this may not always be the case.