using AR middleware to close the connections