some refactoring on example code and Client and Connection classes