Refactoring external commands handling