remove println debugging, refactor connect function