Refactored exec method in cli