Fixes #6773 optimized queries and supporting cookies