basic middlewares logic