refactoring nextCommand