count query moved to own module
refactored middlewares to use count query module