some refactoring
refactored connect method