Tweak cmd handling so it's more DRY
Minor code cleanup