finalize middleware structure