a refactoring for command checking