Refactored client.cpp