Refactoring started for pyclient, not tested, very unstable