added smarter partition query