Refactor connect method and pack method