add base function and session middleware