Fix bugs in interpretation of repository format 2.

Hi,
  I've been playing with an internal package repository and trying to handle some packages with both ST2 and ST3 releases.  I came across some bugs in the release selection code.  I've fixed the ones I found.  I have only tested this with ST3, not ST2, although I can't see anything that would be problematic.

Cheers,

Will             :-}