improve session middleware