refactoring connection flow