code clean up and refactoring for connectActivity