Refactored client command handling