conduct refactoring and made method which wait until connection is established