Fix a few refactoring related bugs in API endpoints