refactoring connect command