move proxy-related code to a better place