Fixed and improved querying