Improved querying functionality