fixed register_middleware