Refactoring Directory and Command logic