Refactor evaluateCommand