refactoring to use external data for connecting