Refactored client and server