Moved the call to the API into a factory