fix order bug, improve query()