Improved algorithm for using available prefixes.