fix/optimization in client handling and memory usage