factorize code in proxy

A few factorization of code inside proxy.cpp to ease its maintenance.