resolved ordering issue.
Database not reliably returning results in table order. added order by
clause to force sorting.

tweaked parser to use list and sort rather than priority queue.