added doc for middleware + fixed where the ids are stored in the query