Add a helper function for the API and start refactoring