refactored the API routes