Small changes to the selection algorithm. The big problem was that the database was inconsistent.