refactor query interface for more flexibility