Clean up and restructure the API