REL-2074: Fixed possible NPE in QPT and cleaned up code.

Minor quibbles, but (a) I would prefer to see this on two lines and (b) it's much faster to ask `isEmpty()` rather than computing `size()` and comparing. So, something like

```java
if (peer == null && !peerSet.isEmpty()) 
    peer = peerSet.iterator().next();
```