Separated actual algorithm from generateList a bit so that we can change
algorithm easier if it doesn't work out.