* Added SortedQueue class and tests.

This is in preparation of using it instead of inline request storage.
* Use SortedQueue making code better.