refactor paths by factoring out some functions
created a middleware for route-params