refactored and redesigned connection part