Refactored setup_client function, not compiled yet