fix bugs and syntax in API routes