Refactor doQuery and add cmd example