upate middleware logic after pull/387; convert connection middleware to new priority syntax