Add priority queue and unit tests.
Reorganize reading code: new frame -> more data -> complete.