refactored client handling in server