Split out proxy logic into its own function.