Brutal refactoring for reusing code between GProxy and JProxy

Added license: Apache 2.0