This looks like an exact copy of smartProxies in the previous function. Maybe split it off in a separate function?