Some bits I came up with while trying to grok the recent changes in thementioned function.Please have a careful look.