cmd related code refactory