Clean up API endpoint code