Replace some inlined code with wrap-ns middleware usage