refactored client and server