Cleanup permalink generation

Fix permalink generation to not contain various smells. See verbose description in the last commit in this PR.
Should `host.count` be cached in a local variable within the method? If we are looping and keep finding a candidate that is taking, we probably don't need to run `host.count` once for every loop.. it's unlikely to change in the few milliseconds since it was run the previous time through the loop (assuming one or more other attempts).