adding multi client handling, refactoring