Restored some features of query.py