code organization and refactoring, client no working properly with pkt loss