[RFC] Spliting two-iteration loops in ExpandBufnames()

Two 2-iteration loops (one inside the other) were present in ExpandBufnames() which have been split.
As in #572