refactoring cmd handling